package com.xqb.modules.controller.ins;

import com.xqb.common.annotation.Log;
import com.xqb.common.core.controller.BaseController;
import com.xqb.common.core.domain.AjaxResult;
import com.xqb.common.core.page.TableDataInfo;
import com.xqb.common.enums.BusinessType;
import com.xqb.common.utils.poi.ExcelUtil;
import com.xqb.modules.domain.po.InsReview;
import com.xqb.modules.service.IInsReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 审核Controller
 *
 * @author xqb
 * @date 2024-10-31
 */
@RestController
@RequestMapping("/ins/review")
public class InsReviewController extends BaseController {
    @Autowired
    private IInsReviewService insReviewService;

    /**
     * 查询审核列表
     */
    @PreAuthorize("@ss.hasPermi('ins:review:list')")
    @GetMapping("/list")
    public TableDataInfo list(InsReview insReview) {
        startPage();
        List<InsReview> list = insReviewService.selectInsReviewList(insReview);
        return getDataTable(list);
    }

    /**
     * 导出审核列表
     */
    @PreAuthorize("@ss.hasPermi('ins:review:export')")
    @Log(title = "审核", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InsReview insReview) {
        List<InsReview> list = insReviewService.selectInsReviewList(insReview);
        ExcelUtil<InsReview> util = new ExcelUtil<InsReview>(InsReview.class);
        util.exportExcel(response, list, "审核数据");
    }

    /**
     * 获取审核详细信息
     */
    @PreAuthorize("@ss.hasPermi('ins:review:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(insReviewService.selectInsReviewById(id));
    }

    /**
     * 新增审核
     */
    @PreAuthorize("@ss.hasPermi('ins:review:add')")
    @Log(title = "审核", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InsReview insReview) {
        return toAjax(insReviewService.insertInsReview(insReview));
    }

    /**
     * 修改审核
     */
    @PreAuthorize("@ss.hasPermi('ins:review:edit')")
    @Log(title = "审核", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InsReview insReview) {
        return toAjax(insReviewService.updateInsReview(insReview));
    }

    /**
     * 删除审核
     */
    @PreAuthorize("@ss.hasPermi('ins:review:remove')")
    @Log(title = "审核", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(insReviewService.deleteInsReviewByIds(ids));
    }
}
